//
//  BaseTabBarController.m
//  CoreGraphicsDemo
//
//  Created by iSolar on 2017/9/14.
//  Copyright © 2017年 nothing. All rights reserved.
//

#import "BaseTabBarController.h"
#import "BaseNavigationController.h"
#import <ColorExtension/UIColor+Hex.h>
#import "MeViewController.h"
#import "ChatViewController.h"
#import "ContactViewController.h"
#import "DiscoverViewController.h"

@interface BaseTabBarController ()

@property (nonatomic, strong) NSArray *imgArray;

@property (nonatomic, strong) NSArray *titleArray;

@property (nonatomic, strong) NSArray *selectImgArr;

@end

@implementation BaseTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    _imgArray = @[@"tabbar_mainframe",@"tabbar_contacts",@"tabbar_discover",@"tabbar_me"];
    _selectImgArr = @[@"tabbar_mainframeHL",@"tabbar_contactsHL",@"tabbar_discoverHL",@"tabbar_meHL"];
    _titleArray = @[@"微信",@"通讯录",@"发现",@"我"];
    
    [[UITabBarItem appearance]setTitleTextAttributes:@{NSFontAttributeName:[UIFont   systemFontOfSize:12],NSForegroundColorAttributeName:[UIColor lightGrayColor]}   forState:UIControlStateNormal];
    
    [[UITabBarItem appearance]setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12],NSForegroundColorAttributeName:[UIColor colorWithHexString:@"0c9c09"]} forState:UIControlStateSelected];
    
    [self setupChildrenControllers];
    
}

- (void)setupChildrenControllers {
    
    ChatViewController *chat = [ChatViewController new];
    [self setUpChildController:chat title:_titleArray[0] imageName:_imgArray[0] selectedImageName:_selectImgArr[0]];
    
    ContactViewController *contact = [ContactViewController new];
    [self setUpChildController:contact title:_titleArray[1] imageName:_imgArray[1] selectedImageName:_selectImgArr[1]];
    
    DiscoverViewController *discover = [DiscoverViewController new];
    [self setUpChildController:discover title:_titleArray[2] imageName:_imgArray[2] selectedImageName:_selectImgArr[2]];
    
    MeViewController *me = [MeViewController new];
    [self setUpChildController:me title:_titleArray[3] imageName:_imgArray[3] selectedImageName:_selectImgArr[3]];
    
}

- (void)setUpChildController:(UIViewController *)childVC title:(NSString *)title imageName:(NSString *)imgName selectedImageName:(NSString *)selectedImageName {

    childVC.title = title;
    childVC.tabBarItem.title = title;
    childVC.tabBarItem.image = [UIImage imageNamed:imgName];
    childVC.tabBarItem.selectedImage = [[UIImage imageNamed:selectedImageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    BaseNavigationController *nav = [[BaseNavigationController alloc]initWithRootViewController:childVC];
    [self addChildViewController:nav];
}

@end
